package com.app.oral.config

data class ApiResponse<T>(
    val code: Int,
    val message: String,
    val data: T? = null
) {
    companion object {
        private const val SUCCESS_CODE = 0
        private const val DEFAULT_ERROR_CODE = -1

        @JvmStatic
        fun <T> ok(): ApiResponse<T> = ApiResponse(SUCCESS_CODE, "success", null)

        @JvmStatic
        fun <T> ok(data: T): ApiResponse<T> = ApiResponse(SUCCESS_CODE, "success", data)

        @JvmStatic
        fun <T> ok(message: String): ApiResponse<T> = ApiResponse(SUCCESS_CODE, message, null)

        @JvmStatic
        fun <T> ok(message: String, data: T): ApiResponse<T> = ApiResponse(SUCCESS_CODE, message, data)

        @JvmStatic
        fun <T> error(message: String): ApiResponse<T> = ApiResponse(DEFAULT_ERROR_CODE, message, null)

        @JvmStatic
        fun <T> error(code: Int, message: String): ApiResponse<T> = ApiResponse(code, message, null)
    }
}